package com.leigang.common.parent.pojo.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.leigang.common.parent.enums.ErrorEnums;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * @author leig-a
 * @version 1.0
 * @desc
 * @date 2023/3/8 14:49
 */
@Getter
@Setter
public class ResponseVo<T> implements Serializable {

    private static final long serialVersionUID = 7688692415246787043L;

    private Integer code;
    private String msg;
    private T data;

    public ResponseVo(){
        this.code = ErrorEnums.SUCCESS.getCode();
        this.msg = ErrorEnums.SUCCESS.getMsg();
    }

    public ResponseVo(Integer code, String msg){
        this();
        this.code = code;
        this.msg = msg;
    }
    public ResponseVo(Integer code, String msg, T data){
        this();
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public ResponseVo(T data){
        this();
        this.data = data;
    }

    public static<T> ResponseVo<T> success(){
        return new ResponseVo<>(ErrorEnums.SUCCESS.getCode(), ErrorEnums.SUCCESS.getMsg());
    }

    public static<T> ResponseVo<T> error(int code, String message, T data){
        return new ResponseVo<>(code, message, data);
    }
}
